package com.yager.config;

import com.yager.config.interceptor.AdminInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author 12866
 * @version 1.0
 * @date 2021/11/21 20:24
 */
@Configuration
public class InterceptorConfig implements WebMvcConfigurer {

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //定义需要拦截的路径
        String[] addPathPatterns = {
                "/admin/**",
        };
        //定义不需要拦截的路径
        String[] excludePathPatterns = {
                "/admin/login",
                "/admin/error"
        };
        registry.addInterceptor(new AdminInterceptor()) //添加要注册的拦截 器对象
                .addPathPatterns(addPathPatterns) //添加需要拦截的路径
                .excludePathPatterns(excludePathPatterns); //添加不需要拦截的路径
    }

}
